import time

import yaml
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

from page.basePage import basePage

with open(r'D:\PycharmProjects\ecShop\autoTest\driver\elements.yml','r',encoding='utf-8') as file:
    elements_config = yaml.safe_load(file)

class search1Page(basePage):
    url = "http://localhost:8800/ecshop/index.php"
    classify_select = By.XPATH,elements_config['search1_page']['classify_select']
    search_frm = By.XPATH,elements_config['search1_page']['search_frm']
    search_btn = By.XPATH,elements_config['search1_page']['search_btn']
    msg_context1 = By.XPATH,elements_config['search1_page']['msg_context1']

    def select_goods(self):
        ele = self.find_Element(self.classify_select)
        select_ele = Select(ele)
        select_ele.select_by_index(1)

    def send_searchGoods(self,goods):
        self.find_Element(self.search_frm).send_keys(goods)

    def click_search(self):
        self.find_Element(self.search_btn).click()

    def fun_search1(self,goods):
        time.sleep(2)
        self.open(self.url)
        self.select_goods()
        self.send_searchGoods(goods)
        self.click_search()
        time.sleep(2)

    def fun_search1alert(self,goods):
        time.sleep(2)
        self.open(self.url)
        self.select_goods()
        self.send_searchGoods(goods)
        time.sleep(2)











